﻿using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using iOSClub.App.Share;

namespace iOSClub.App.Desktop.Converters;

public class UserIdentityConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string name)
        {
            return string.IsNullOrEmpty(name) ? name : MemberModel.IdentityDictionary[name];
        }

        return value;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        => value;
}

public class UserImageConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string gender)
        {
            if (string.IsNullOrEmpty(gender)) return gender;
            return new Bitmap(AssetLoader.Open(new Uri($"avares://iOSClub.App.Desktop/Assets/{gender}生.png")));
        }

        return value;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        => value;
}